<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加用户</title>
<link href="${ctx }/css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/js/niceValidator/jquery.validator.css" />
<link href="${ctx }/css/jquery.multiSelect.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/js/layui/css/layui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="${ctx }/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctx }/js/niceValidator/jquery.validator.js"></script>
<script type="text/javascript" src="${ctx }/js/niceValidator/local/zh_CN.js"></script>
<script type="text/javascript" src="${ctx }/js/common.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.multiSelect.js"></script>

<script>
	$(document).ready(function(){
		$("#submitBtn").click(function(){
			submitForms();
		});
		
		$("#rIdSel").multiSelect({
	        selectAll: false,
	        noneSelected: '请选择角色',
	        oneOrMoreSelected: '*'
	    });
	});
	var index = parent.layer.getFrameIndex(window.name);
	//添加用户
	function submitForms(){
		$("#submitForm").trigger("validate");
		instance = $("#submitForm").data("validator");
		if(instance.isFormValid()){
			var rIds=$("#rIdSel").selectedValuesString();
			if(rIds==''){
				layer.alert('请选择角色', {icon: 2});
				return;
			}
			var loadi = layer.load(3);
			$("#roleIds").val(rIds);
			var datajson=$("#submitForm").serialize();
			$.ajax({
				type:"POST",
				url:"${ctx}/sysman/systemAdmin/addSystemAdmin.do",
				data:datajson,
				dataType:"json",
				success:function(data){
					layer.close(loadi);
					if(data.status=='SUCCESS'){
						window.parent.baseSearchQuery('Refresh');
						window.parent.baseBottomMsgOpen('添加成功');
						window.parent.layer.close(index);
					}else{
						layer.alert(data.msg);
					}
				}
			});
		}
	}
</script>
<style type="text/css">
	HTML {
		font-family: Arial, Helvetica, sans-serif;
		font-size: 12px;
	}
	
	H2 {
		font-size: 14px;
		font-weight: bold;
		margin: 1em 0em .25em 0em;
	}
	
	P {
		margin: 1em 0em;
	}
</style>
</head>
<body style="min-width:700px;">
<div class="listNavTitle">
  <p>
    <label>系统管理 ></label>
    <label>用户管理</label>
  </p>
</div>
<div class="formbody">
  <div class="formtitle"><span>新增用户</span></div>
<form id="submitForm">
  <ul class="forminfo">
    <li>
      <label>姓名</label>
      <input name="systemRealName" type="text" class="dfinput"  data-rule="姓名:required;"/>
    </li>
    <li>
      <label>用户名</label>
      <input name="systemUserName" type="text" class="dfinput"  data-rule="用户名:required;username;remote[${ctx }/sysman/systemAdmin/checkUserName.do?id=0];"/>
    </li>
    <li>
      <label>角色</label>
      <input type="hidden" name="roleCodes" id="roleIds" />
      <select multiple="multiple" id="rIdSel" style="width:334px;">
      	<c:forEach items="${systemRoleList}" var="item">
      		<option value="${item.roleCode }">${item.roleName }</option>
      	</c:forEach>
      </select>
    </li>
    <li>
      <label>密码</label>
      <input name="systemPassword" type="password" class="dfinput" data-rule="密码:required;password;"/>
    </li>
    <li>
      <label>联系方式</label>
      <input name="systemCell" type="text" class="dfinput" />
    </li>
    <li>
      <label>邮箱</label>
      <input name="systemEmail" type="text" class="dfinput" />
    </li>
    <li>
      <label>&nbsp;</label>
      <button class="layui-btn layui-btn-normal" type="button" class="btn" id="submitBtn">确认保存</button>
    </li>
  </ul>
</form>
</div>
</body>
</html>

 